<?php
namespace app\index\controller;

use think\Db;
use think\facade\Request;

/**
* 首页控制器
*/
class Index extends Base{

    public function initialize(){
        parent::initialize();

    }
    public function index()
    {
    	$archives = DB::name('article')
                ->where('status',1)
                ->order('create_time DESC,id DESC')
                ->paginate(5)
                ->each(function ($item,$key){
                    $roles = Db::name('category')->where([['id','in',$item['catid']]])->column('catname');
                    $item['catname'] = '';
                    if($roles)
                        $item['catname'] = implode(',',$roles);
                    return $item;
                });
        $where = [
            'status' => 1,
            'flag' =>1,
        ];
        $is_archives = DB::name('article')
            ->where($where)
            ->order('create_time DESC,id DESC')
            ->paginate(4)
            ->each(function ($item,$key){
                $roles = Db::name('category')->where([['id','in',$item['catid']]])->column('catname');
                $item['catname'] = '';
                if($roles)
                    $item['catname'] = implode(',',$roles);
                return $item;
            });
        $viewDate = [
            'archives' => $archives,
            'is_archives' => $is_archives
        ];
    	$this->assign($viewDate);
        return $this->fetch();
    }
}
